package Module_4;

// Beispiel fuer einen Runnable Thread: RunPingPong.java

public class RunPingPong implements Runnable
{
  private String word;
  private int delay;

  private RunPingPong( String wd, int del )  //only used in this method. declared private
  {
    word=wd;
    delay=del;
  }

  public void run()
  {
    try
    {
      for (int i = 0; i < (8000/this.delay); i++)     /*Endlosschleife ersetzt mit 8 Sekunden Programmdauer*/
      {
        System.out.print( word + " ");
        Thread.sleep( delay );
      }
    }
    catch ( InterruptedException e ) { System.out.println(e); } //return was unnecessary; exception shoul be displayed
  }

  public static void main( String[] args )
  {
    RunPingPong ping = new RunPingPong("Ping?",200);
    RunPingPong pong = new RunPingPong("Pong! \n",555);
    new Thread(ping).start();
    new Thread(pong).start();
  }
}